package com.yida.gwj.config.service.impl;

import com.yida.common.core.exception.ServiceException;
import com.yida.common.core.utils.DateUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.api.domain.GwjConfStepConfigInfo;
import com.yida.gwj.config.mapper.GwjConfStepConfigInfoMapper;
import com.yida.gwj.config.service.IGwjConfStepConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务步骤配置信息Service业务层处理
 *
 * @author lqq
 * @date 2022-12-13
 */
@Service
public class GwjConfStepConfigInfoServiceImpl implements IGwjConfStepConfigInfoService {

	@Autowired
	private GwjConfStepConfigInfoMapper gcStepConfigInfoMapper;

	/**
	 * 查询业务步骤配置信息列表
	 *
	 * @param gcStepConfigInfo 业务步骤配置信息
	 * @return 业务步骤配置信息
	 */
	@Override
	public List<GwjConfStepConfigInfo> selectGwjConfStepConfigInfoList(GwjConfStepConfigInfo gcStepConfigInfo) {
		return gcStepConfigInfoMapper.selectGwjConfStepConfigInfoList(gcStepConfigInfo);
	}


	/**
	 * 根据配置ID查询步骤配置信息
	 *
	 * @param configId 配置ID
	 * @return 结果
	 */
	@Override
	public GwjConfStepConfigInfo selectGwjConfStepConfigInfoByConfigId(Long configId) {
		return gcStepConfigInfoMapper.selectGwjConfStepConfigInfoByConfigId(configId);
	}

	/**
	 * 新增业务步骤配置信息
	 *
	 * @param gcStepConfigInfo 业务步骤配置信息
	 * @return 结果
	 */
	@Override
	public int insertGwjConfStepConfigInfo(GwjConfStepConfigInfo gcStepConfigInfo) {
		if (StringUtils.isNotNull(gcStepConfigInfoMapper.selectGwjConfStepConfigInfoByConfigName(gcStepConfigInfo.getName()))) {
			throw new ServiceException("配置名称已存在");
		}
		if (StringUtils.isNotNull(gcStepConfigInfoMapper.selectGwjConfStepConfigInfoByConfigCode(gcStepConfigInfo.getCode()))) {
			throw new ServiceException("配置编码已存在");
		}
		gcStepConfigInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gcStepConfigInfo.setCreateTime(DateUtils.getNowDate());
		return gcStepConfigInfoMapper.insertGwjConfStepConfigInfo(gcStepConfigInfo);
	}

	/**
	 * 修改业务步骤配置信息
	 *
	 * @param gcStepConfigInfo 业务步骤配置信息
	 * @return 结果
	 */
	@Override
	public int updateGwjConfStepConfigInfo(GwjConfStepConfigInfo gcStepConfigInfo) {
		gcStepConfigInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gcStepConfigInfo.setUpdateTime(DateUtils.getNowDate());
		return gcStepConfigInfoMapper.updateGwjConfStepConfigInfo(gcStepConfigInfo);
	}

	/**
	 * 查询业务步骤配置信息
	 *
	 * @param stepId 业务步骤ID
	 * @return 业务步骤集合
	 */
	@Override
	public List<String> selectGwjConfStepConfigInfoCodeListByStepId(Long stepId) {
		return gcStepConfigInfoMapper.selectGwjConfStepConfigInfoCodeListByStepId(stepId);
	}
}
